﻿Public Class FormDepositosListado
    Dim classController As New Class_RC_Controller.rc_Depositos()

    Private m_frmDeposito As FrmDepositos
    Public Property frmDeposito() As FrmDepositos
        Get
            Return m_frmDeposito
        End Get
        Set(ByVal value As FrmDepositos)
            m_frmDeposito = value
        End Set
    End Property

    Private Sub FormDepositosListado_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        dgDeposito.AutoGenerateColumns = False
        CargarDeposito()
    End Sub
    Private Sub CargarDeposito()
        Dim dt As New DataTable
        dt = classController.get_Depositos_All(oiml.dbConn, 0, txtDescripcion.Text)
        dgDeposito.DataSource = dt
    End Sub

    Private Sub btnCancelar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancelar.Click
        Me.Close()
    End Sub

    Private Sub btnEditar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEditar.Click
        Try
            If dgDeposito.SelectedRows.Count > 0 Then
                Dim CodDeposito As New Integer
                CodDeposito = dgDeposito.SelectedRows(0).Cells(0).Value

                If frmDeposito Is Nothing Then
                    frmDeposito = New FrmDepositos
                    frmDeposito.coddeposito = CodDeposito
                    frmDeposito.ShowDialog()
                    CargarDeposito()
                    frmDeposito.Dispose()
                    frmDeposito = Nothing
                Else
                    frmDeposito.coddeposito = CodDeposito
                    frmDeposito.ShowDialog()
                End If
            End If
        Catch ex As Exception
            MessageBox.Show("Error: " & ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub


    Private Sub txtBuscar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtBuscar.Click
        CargarDeposito()
    End Sub

    Private Sub dgDeposito_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles dgDeposito.DoubleClick
        btnEditar_Click(sender, e)
    End Sub

    Private Sub dgDeposito_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles dgDeposito.KeyDown
        If e.KeyCode = Keys.Enter Then
            btnEditar_Click(sender, e)
        End If
    End Sub

    Private Sub btnNuevo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNuevo.Click
        '    If frmciudad Is Nothing Then
        frmDeposito = New FrmDepositos()
        frmDeposito.ShowDialog()
        CargarDeposito()
    End Sub
End Class